/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * IHMSimulatorUpdateDate.java
 *
 * Created on 20 janv. 2011, 23:21:35
 */

package IHM;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import javax.swing.JOptionPane;

/**
 *
 * @author Pierre
 */
public class IHMSimulatorUpdateDate extends javax.swing.JDialog {

    private IHMSimulator parent;
    /** Creates new form IHMSimulatorUpdateDate */
    public IHMSimulatorUpdateDate(IHMSimulator parent, boolean modal) {
        super(parent, modal);
        initComponents();
        this.parent = parent;
    }

    public void showPopup()
    {
        jTF_Date.setText(parent.getCurrentSimulationDate());
        this.setLocationRelativeTo(parent);
        this.setVisible(true);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jBtn_OK = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        jTF_Date = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel1.setText("Mise à jour de la date");
        getContentPane().add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 320, -1));

        jBtn_OK.setText("OK");
        jBtn_OK.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtn_OKActionPerformed(evt);
            }
        });
        getContentPane().add(jBtn_OK, new org.netbeans.lib.awtextra.AbsoluteConstraints(110, 90, 110, -1));

        jLabel2.setText("Date :");
        getContentPane().add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 40, 70, 25));
        getContentPane().add(jTF_Date, new org.netbeans.lib.awtextra.AbsoluteConstraints(90, 40, 200, 25));

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jBtn_OKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBtn_OKActionPerformed
        try {
            parent.updateDate(new SimpleDateFormat("MM-dd-yyyy HH:mm:ss").parse(jTF_Date.getText()));
            this.setVisible(false);
        }
        catch (ParseException ex) {
            JOptionPane.showMessageDialog(this, "Vous devez saisir une date dans le format MM-dd-yyyy HH:mm:ss.");
        }
    }//GEN-LAST:event_jBtn_OKActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jBtn_OK;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JTextField jTF_Date;
    // End of variables declaration//GEN-END:variables

}
